package com.niiwoo.civet.mobile.shiro;

import com.alibaba.dubbo.config.annotation.Reference;
import com.niiwoo.civet.user.dto.response.OrganizationInfoRespDTO;
import com.niiwoo.civet.user.service.OrganizationDubboService;
import com.niiwoo.tripod.base.enums.UserTypeEnum;
import com.niiwoo.tripod.web.shiro.OrgInvestorDetailService;
import com.niiwoo.tripod.web.shiro.OrgUserAuthPrincipal;
import org.springframework.stereotype.Component;

@Component
public class OrgInvestorDetailServiceImpl implements OrgInvestorDetailService {

    @Reference(version = "1.0.0")
    private OrganizationDubboService organizationDubboService;

    @Override
    public OrgUserAuthPrincipal selectOrganizationInfoByAgentUserName(String userName) {
        OrganizationInfoRespDTO organizationInfoRespDTO = organizationDubboService.selectOrganizationInfoByAgentUserName(userName);
        OrgUserAuthPrincipal orgUserAuthPrincipal = new OrgUserAuthPrincipal();
        orgUserAuthPrincipal.setType(organizationInfoRespDTO.getType());
        orgUserAuthPrincipal.setCredentials(organizationInfoRespDTO.getPassword());
        orgUserAuthPrincipal.setPrincipal(organizationInfoRespDTO.getAgentUserName());
        orgUserAuthPrincipal.setSalt(organizationInfoRespDTO.getSalt());
        orgUserAuthPrincipal.setUserId(organizationInfoRespDTO.getId());
        orgUserAuthPrincipal.setUserType(UserTypeEnum.ORGANIZATION);
//        orgUserAuthPrincipal.setDeviceType("H5");
//        orgUserAuthPrincipal.setReserve();
        return orgUserAuthPrincipal;
    }
}
